package com.sky.controller.admin;

import com.fasterxml.jackson.core.PrettyPrinter;
import com.sky.dto.*;
import com.sky.entity.Orders;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.admin.OrderService;
import com.sky.vo.OrderStatisticsVO;
import io.netty.handler.codec.serialization.ObjectEncoder;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.type.Alias;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController("adminOrderController")
@RequestMapping("/admin/order")
@Slf4j
@Api(tags = "管理端订单模块对应接口")
public class OrderController {
    @Autowired
    private OrderService adminOrderService;

    @GetMapping("conditionSearch")
    @ApiOperation("订单搜索业务接口")
    public Result<PageResult> conditionSearch(OrdersPageQueryDTO dto){
        Result<PageResult> result = adminOrderService.getOrderPageInfo(dto);
        return result;
    }


    @GetMapping("details/{id}")
    @ApiOperation("查看订单详情对应接口")
    public Result<Orders> getOrderDetailById(@PathVariable Long id){
        Result<Orders> result = adminOrderService.getOrderDetailById(id);
        return result;
    }

    @GetMapping("statistics")
    @ApiOperation("统计各个状态订单数量的对应接口")
    public Result<OrderStatisticsVO> getOrderStatusCount(){
        Result<OrderStatisticsVO> result = adminOrderService.getOrderStatusCount();
        return result;
    }

    @PutMapping("confirm")
    @ApiOperation("管理端接单对应接口")
    public Result<Object> confirmOrder(@RequestBody OrdersConfirmDTO dto){
        log.info("接单信息为：{}",dto);
        Result<Object> result = adminOrderService.confirmOrderById(dto);
        return result;
    }

    @PutMapping("rejection")
    @ApiOperation("拒单")
    public Result<Object> rejectionOrders(@RequestBody OrdersRejectionDTO dto){
        log.info("拒单信息为：{}",dto);
        Result<Object> result = adminOrderService.rejectionOrder(dto);

        // todo ： 涉及微信退款接口，暂不完成对应接口 空实现
        return result;
    }

    @PutMapping("delivery/{id}")
    @ApiOperation("派送订单对应接口")
    public Result<Object> deliveryOrders(@PathVariable Long id){
        log.info("派单信息为：{}",id);
        Result<Object> result = adminOrderService.deliveryOrders(id);
        return result;
    }


    @PutMapping("cancel")
    @ApiOperation("客户端取消订单对应接口")
    public Result<Object> cancelOrders(@RequestBody OrdersCancelDTO dto){
        Result<Object> result = adminOrderService.cancelOrder(dto);
        return result;
    }

    @PutMapping("complete/{id}")
    @ApiOperation("完成订单对应接口")
    public Result<Object> completeOrders(@PathVariable Long id){
        Result<Object> result = adminOrderService.completeOrders(id);
        return result;
    }


}
